<template>
  <div>
    <div style="margin: 3px;">
      <h1 style="font-size: 30px;text-align: center;">{{site.siteName}}</h1>
      <el-button style="float: left;" @click="Pass" type="primary">修改密码</el-button>
      <el-button style="float: left;margin-left: 22px;"  v-if="this.siteRole==0?true:false" @click="updateBtn(site)" type="primary">修改站点信息</el-button>
    </div>

    <el-dialog  title="修改站点信息" :visible.sync="showPass" width="35%" :before-close="handleClose">
      <el-form ref="updatePass" :model="updatePass" label-width="100px">
        <el-form-item label="登录密码">
          <el-input v-model="updatePass.oldPass" type="password"></el-input>
        </el-form-item>
        <el-form-item label="新密码">
          <el-input v-model="updatePass.newPass"  type="password" show-password></el-input>
        </el-form-item>
        <el-form-item label="确认密码">
          <el-input v-model="updatePass.confirmPass"  type="password"  show-password></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel1">取 消</el-button>
        <el-button type="primary" @click="confirm1">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 展现信息列表 -->
    <div style="border: 1px silver solid;width: 1200px;height: 500px;margin-top: 42px;">
      <el-form ref="site" disabled :model="site" label-width="100px">
        <el-col :span="11">
          <el-form-item></el-form-item>
          <el-form-item label="站点账号">
            <el-input v-model="site.siteAccountDTO.siteAccount"></el-input>
          </el-form-item>
          <el-form-item label="站点状态">
            <el-input v-model="site.siteState==0?'正常':site.siteState==1?'禁用':'删除'" ></el-input>
          </el-form-item>
          <el-form-item label="站点评分">
            <el-input v-model="site.siteStore"></el-input>
          </el-form-item>
          <el-form-item label="创建时间">
            <el-input v-model="site.siteAccountDTO.creatTime"></el-input>
          </el-form-item>
          <el-form-item label="操作人">
            <el-input v-model="site.siteAccountDTO.operator"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item></el-form-item>
          <el-form-item label="站点电话">
            <el-input v-model="site.sitePhone"></el-input>
          </el-form-item>
          <el-form-item label="站点地址">
            <el-input v-model="site.siteAddress"></el-input>
          </el-form-item>
          <el-form-item label="营业时间">
            <el-time-picker value-format='HH:mm:ss' v-model="site.siteStartTime" :picker-options="{
                selectableRange: '00:00:00 - 23:59:59'
              }" placeholder="开始时间">
            </el-time-picker>
            --------
            <el-time-picker value-format='HH:mm:ss' v-model="site.siteEndTime" :picker-options="{
                selectableRange: '00:00:00 - 23:59:59'
              }" placeholder="结束时间">
            </el-time-picker>
          </el-form-item>
          <el-form-item label="站点账号">
            <el-input v-model="site.payAccount"></el-input>
          </el-form-item>
        </el-col>
      </el-form>
      <!-- 修改站点信息 -->
      <el-dialog  title="修改站点信息" :visible.sync="dialogVisible" width="35%" :before-close="handleClose">
        <el-form ref="updateSite" :model="updateSite" label-width="100px">
          <el-form-item label="站点名称">
            <el-input v-model="updateSite.siteName"></el-input>
          </el-form-item>
          <el-form-item label="站点电话">
            <el-input v-model="updateSite.sitePhone"></el-input>
          </el-form-item>
          <el-form-item label="站点地址">
            <el-input v-model="updateSite.siteAddress"></el-input>
          </el-form-item>
          <el-form-item label="开门时间">
            <el-time-picker value-format='HH:mm:ss' v-model="updateSite.siteStartTime" :picker-options="{
                  selectableRange: '00:00:00 - 23:59:59'
                }" placeholder="选择开始时间">
            </el-time-picker>
          </el-form-item>
          <el-form-item  label="关门时间">
            <el-time-picker value-format='HH:mm:ss' v-model="updateSite.siteEndTime" :picker-options="{
                  selectableRange: '00:00:00 - 23:59:59'
                }" placeholder="选择结束时间">
            </el-time-picker>
          </el-form-item>
          <el-form-item label="站点钱包">
            <el-input v-model="updateSite.payAccount"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="cancel">取 消</el-button>
          <el-button type="primary" @click="confirm">确 定</el-button>
        </span>
      </el-dialog>
    </div>

  </div>
</template>

<script>
  export default {
    name: "SiteInfo",
    data() {
      return {
        updatePass:{},
        showPass:false,
        dialogVisible: false,
        updateSite: {
          siteName:'',
          sitePhone:'',
          siteAddress:'',
          siteStartTime:'',
          siteEndTime:'',
          payAccount:''
        },
        site: {
          siteAccountDTO: {}
        },
        siteRole:''
      }
    },
    methods: {



      //修改密码中的确定按钮
      confirm1(){
        let oldPass=this.updatePass.oldPass
        let newPass=this.updatePass.newPass
        let confirmPass=this.updatePass.confirmPass
        if (oldPass==''||oldPass==null) {
          alert("请输入登录密码")
        }else if (newPass==''||newPass==null) {
          alert("请输入新密码")
        } else if(confirmPass==''||confirmPass==null){
          alert("请输入确认密码")
        } else if(newPass!=confirmPass){
          alert("新密码与确认密码不一致")
          this.updatePass.confirmPass = ''
        }else{
          this.$http.post("/site/siteAccount/updatePass.site",{
            newPass:newPass,
            oldPass:oldPass
          }).then(resp=>{
            if (resp.data.code == 200) {
              alert(resp.data.message)
              this.updatePass = {}
              this.showPass = false
              this.$http.post("/site/siteAccount/logout.site").then(resp=>{
                localStorage.removeItem("ecologyToken")
                localStorage.removeItem("siteAccountMessage")
                this.$router.push("/index")
              })
            } else{
               alert(resp.data.message)
            }
          })
        }
      },

      //修改密码中的取消按钮
      cancel1(){
        this.updatePass ={}
        this.showPass = false
      },

      //修改密码按钮
      Pass(){
        this.showPass = true
      },

      // 确定按钮
      confirm() {
        var start = this.updateSite.siteStartTime
        var end = this.updateSite.siteEndTime
        if(end>start){
          this.$http.post("/site/siteInfo/siteUpdateInfo.site",this.updateSite).then(resp=>{
            alert(resp.data.message)
            this.showSiteInfo()
            this.dialogVisible = false
          })
        }else if(start==''||start==null){
          alert("开始时间不为空")
        }else if(end==''||end==null){
          alert("结束时间不为空")
        }else{
          alert("结束时间必须大于开始时间")
        }
      },

      // 取消按钮
      cancel() {
        this.updateSite.siteName=''
        this.updateSite.siteAddress=''
        this.updateSite.sitePhone=''
        this.updateSite.siteStartTime=''
        this.updateSite.siteEndTime=''
        this.updateSite.payAccount=''
        this.showSiteInfo()
        this.dialogVisible = false
      },

      //修改站点按钮
      updateBtn(site) {
        console.log(site)
        this.updateSite.siteName=site.siteName
        this.updateSite.siteAddress=site.siteAddress
        this.updateSite.sitePhone=site.sitePhone
        this.updateSite.siteStartTime=site.siteStartTime
        this.updateSite.siteEndTime=site.siteEndTime
        this.updateSite.payAccount=site.payAccount
        let form = this.updateSite
        // 深拷贝处理
        let str=JSON.stringify(form)
        let updateForm=JSON.parse(str)
        this.dialogVisible = true
      },
      //关闭弹窗
      handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
      },

      //展示站点信息
      showSiteInfo() {
        this.$http.post("/site/siteInfo/siteSelectOne.site").then(resp => {
          if(resp.data.code==200){
            this.site = resp.data.data
          }else{
            this.site = {}
          }

        })
      },

      showSiteAccount(){
       let siteAccount = JSON.parse(localStorage.getItem("siteAccountMessage"))       
       this.siteRole = siteAccount.siteRole
      }
    },
    created() {
      this.showSiteInfo()
      this.showSiteAccount()
    }
  }
</script>

<style>
</style>
